﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BOMS.DAL;
using BOMS.Utility;
namespace BOMS.WebUI
{
    public partial class sysChangePwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["userId"]= HttpContext.Current.User.Identity.Name;
                showUserInfo(ViewState["userId"].ToString());
            }
        }
        private void showUserInfo(String userId)
        {
            DataTable dt = new DataTable();
            dt = SysAdmin.getUserInfoById(userId);
            this.userName.Text = dt.Rows[0]["userName"].ToString();
            this.name.Text = dt.Rows[0]["name"].ToString();
            ViewState["pwdDb"] = dt.Rows[0]["pwd"].ToString();
        }
      
        protected void add_Click(object sender, EventArgs e)
        {
            string pwdOld=this.pwdOld.Text;
            pwdOld = StringOp.HashData(pwdOld);
            string pwdNew = this.pwdNew.Text;
            Type cstype = this.GetType();

            if (ViewState["pwdDb"].ToString() == pwdOld)
            {
                Boolean isSuccess = SysAdmin.resetPwd(ViewState["userId"].ToString(), pwdNew);
                if (isSuccess)
                {
                    ClientScript.RegisterStartupScript(cstype, "key", "<script>alert('修改成功！');</script>");
                }
                else
                {
                    ClientScript.RegisterStartupScript(cstype, "key", "<script>alert('修改失败！');</script>");
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(cstype, "key", "<script>alert('旧密码输入错误！');</script>");

            }
        }
    }
}